package com.argrace.smart;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.SystemClock;
import android.support.multidex.MultiDex;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.sdk.android.openaccount.Environment;
import com.alibaba.wireless.security.open.SecurityGuardManager;
import com.alibaba.wireless.security.open.staticdatastore.IStaticDataStoreComponent;
import com.aliyun.alink.AlinkSDK;
import com.aliyun.alink.alirn.RNGlobalConfig;
import com.aliyun.alink.alirn.rnpackage.biz.BizPackageHolder;
import com.aliyun.alink.bone.CdnEnv;
import com.aliyun.alink.business.account.OALoginBusiness;
import com.aliyun.alink.business.alink.ALinkBusinessEx;
import com.aliyun.alink.business.alink.ALinkEnv;
import com.aliyun.alink.business.helper.ChannelBindHelper;
import com.aliyun.alink.business.login.IAlinkLoginCallback;
import com.aliyun.alink.sdk.net.anet.api.AError;
import com.aliyun.alink.sdk.net.anet.api.persistentnet.EventDispatcher;
import com.aliyun.alink.sdk.net.anet.api.persistentnet.IOnPushListener;
import com.aliyun.alink.sdk.net.anet.api.transitorynet.TransitoryRequest;
import com.aliyun.alink.sdk.net.anet.api.transitorynet.TransitoryResponse;
import com.aliyun.alink.utils.ALog;
import com.argrace.smart.base.ConstantConfigure;
import com.argrace.smart.entity.Key_ValueEntity;
import com.argrace.smart.envconfig.EnvConfigure;
import com.argrace.smart.model.LocalDb_AnJianTable;
import com.argrace.smart.model.LocalDb_DeviceNameAndRoomNameTable;
import com.argrace.smart.model.LocalDb_DeviceSyncTable;
import com.argrace.smart.model.LocalDb_QingJingTable;
import com.argrace.smart.model.LocalDb_QingJing_DeviceTable;
import com.argrace.smart.model.LocalDb_RelationDeviceTable;
import com.argrace.smart.model.LocalDb_RoomNameTable;
import com.argrace.smart.model.LocalDb_ShuangKongFuSheBeiTable;
import com.argrace.smart.util.AlinkHttpUtil;
import com.argrace.smart.util.utils;
import com.facebook.react.FrescoPackage;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.cookie.store.PersistentCookieStore;
import com.lzy.okgo.model.HttpHeaders;
import com.taobao.accs.ACCSManager;
import com.taobao.accs.IAppReceiver;
import com.taobao.accs.client.AccsConfig;
import com.taobao.accs.common.Constants;
import com.videogo.openapi.EZOpenSDK;

import org.android.spdy.SpdyProtocol;
import org.litepal.LitePalApplication;
import org.litepal.crud.DataSupport;
import org.litepal.tablemanager.Connector;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by argrace_dev_1 on 2018/1/29.
 */

public class ArgraceApplication extends LitePalApplication {

    private static final String TAG = "ArgraceApplication";
    private ALinkEnv alinkEnv = ALinkEnv.Online;
    private CdnEnv cdnEnv = CdnEnv.Release;
    public static String Device_ID = "";
    private String appkey = "24783578";
    public static boolean is_RefreshQingJingTable = false;
    public static boolean is_RefreshRoomTable = false;
    public static boolean is_RefreshWangGuanList = false;
    private String s = "{\"id\":0,\"method\":\"open.callback.unify.deviceStatusChange\",\"params\":{\"data\":{\"Refresh\":{\"valueName\":\"刷新\",\"when\":\"1520221357\",\"value\":\"1\",\"attrName\":\"信息刷新\"},\"Rssi\":{\"when\":\"1520221861\",\"value\":\"-30\",\"attrName\":\"接收信号强度\"},\"MotionAlarm\":{\"valueName\":\"检测有人\",\"when\":\"1520222267\",\"value\":\"1\",\"attrName\":\"红外报警状态\"},\"BatteryPercentage\":{\"when\":\"1518148258\",\"value\":\"100\",\"attrName\":\"电池电量\"},\"TamperAlarm\":{\"valueName\":\"正常\",\"when\":\"1518148257\",\"value\":\"0\",\"attrName\":\"防撬报警\"},\"onlineState\":{\"when\":\"1520222267\",\"value\":\"on\"}},\"uuid\":\"7E57736D15A2B97F51CD1F6B9B9BE21E\"},\"request\":{\"hostType\":\"\",\"host\":\"\",\"version\":\"\",\"account\":\"4398615251941\"},\"system\":{\"sign\":\"e0dc356f0080336bbc998f542c79257e\",\"time\":\"1520222267\",\"key\":\"24783578\"}}";

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i("info", "ArgraceApplication.oncreate()");
        Connector.getDatabase();
        //清除表数据
//        DataSupport.deleteAll(LocalDb_RelationDeviceTable.class);
//        DataSupport.deleteAll(LocalDb_AnJianTable.class);
//        DataSupport.deleteAll(LocalDb_QingJingTable.class);
//        DataSupport.deleteAll(LocalDb_QingJing_DeviceTable.class);
//        DataSupport.deleteAll(LocalDb_RoomNameTable.class);
//        DataSupport.deleteAll(LocalDb_DeviceNameAndRoomNameTable.class);
        initEnv();
        getAppKey();

        initAccs();

        initAlinkSDK();
        initOkgo();
        initYingShi();
//二维码相关，暂不需要
//        QRCodeHelper.init(this);
    }

    //事件配置?不是很清楚，暂放
    private void initEnv() {
        EventDispatcher.getInstance().registerOnPushListener(new IOnPushListener() {
            @Override
            public void onCommand(String s) {
//                Log.i("info", "收到推送" + s);
                Intent intent_b = new Intent();
                intent_b.setAction("com.example.broadcast");
                intent_b.putExtra("msg", s);
                sendBroadcast(intent_b);
                com.alibaba.fastjson.JSONObject obj = JSON.parseObject(s);
                //如果是情景开关发送过来的消息,处理情景的推送start
                com.alibaba.fastjson.JSONObject keyFobValue = null;
                try {
                    keyFobValue = obj.getJSONObject("params").getJSONObject("data").getJSONObject("KeyFobValue");
                } catch (Exception e) {
                    return;
                }
                if (keyFobValue != null) {
                    List<LocalDb_AnJianTable> beans = DataSupport.where("uuid = ?", obj.getJSONObject("params").getString("uuid")).find(LocalDb_AnJianTable.class);
                    //从数据库查找相关uuid的设备,
                    if (beans != null && beans.size() > 0) {
                        //如果有数据，查询情景表
                        for (int i = 0; i < beans.size(); i++) {
                            if (beans.get(i).getKey().equals(keyFobValue.getString("value"))) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                        }
                    }
                }
//
                doRelationDevice(obj);
//                dosyncDevice(obj);
            }

            @Override
            public boolean filter(String s) {
//                Log.i("info", "收到下推filter" + s);
                return true;
            }
        }, true);
        EnvConfigure.init(this);
        if (EnvConfigure.aLinkEnv != null) {
            alinkEnv = EnvConfigure.aLinkEnv;
        } else {
            EnvConfigure.saveAlinkEnv(this, alinkEnv);
        }

        if (EnvConfigure.cdnEnv != null) {
            cdnEnv = EnvConfigure.cdnEnv;
        } else {
            EnvConfigure.saveCDNEnv(this, cdnEnv);
        }
    }

    private void getAppKey() {
        try {
            int index;
            if (alinkEnv == ALinkEnv.Daily) {
                index = 2;
            } else {
                index = 0;
            }
            // initialize security guard
            // if only read appKey, skip initialize is ok
            SecurityGuardManager.getInitializer().initialize(getApplicationContext());

            SecurityGuardManager sgMgr = SecurityGuardManager.getInstance(this);
            if (sgMgr != null) {
                IStaticDataStoreComponent sdsComp = sgMgr.getStaticDataStoreComp();
                if (sdsComp != null) {
                    appkey = sdsComp.getAppKeyByIndex(index, "");
                    Log.i("info", "安全图片的的key是" + appkey);
                    ALog.d(TAG, appkey);
                }
            }
        } catch (Exception e) {
            ALog.d(TAG, "");
        }
    }

    // init ACCS
    private void initAccs() {
        Log.i("info", "-*-*-*-*-*-*-");

        int env = Constants.DEBUG;
//        if (alinkEnv == ALinkEnv.Preview) {
//            env = Constants.PREVIEW;
//        } else if (alinkEnv == ALinkEnv.Online) {
        env = Constants.RELEASE;
//        }

        AccsConfig.setSecurityGuardOff(AccsConfig.SECURITY_TYPE.SECURITY_OPEN);
        AccsConfig.setGroup(AccsConfig.ACCS_GROUP.OPEN);
        AccsConfig.setAccsCenterHosts("openacs.m.taobao.com",
                "openacs.m.taobao.com", "openacs.m.taobao.com");
        AccsConfig.setChannelHosts("openjmacs.m.taobao.com",
                "openjmacs.m.taobao.com", "openjmacs.m.taobao.com");
        AccsConfig.setAccsCenterIps(new String[]{"140.205.160.76"},
                new String[]{"140.205.172.12"},
                new String[]{"10.125.50.231"});
        AccsConfig.setChannelIps(new String[]{"140.205.163.94"},
                new String[]{"140.205.172.12"},
                new String[]{"10.125.50.231"});
        AccsConfig.setTnetPubkey(SpdyProtocol.PUBKEY_SEQ_OPEN, SpdyProtocol.PUBKEY_SEQ_OPEN);
        AccsConfig.setChannelReuse(true);

        com.taobao.accs.utl.ALog.setUseTlog(true);
        anet.channel.util.ALog.setUseTlog(true);
        ACCSManager.setMode(this, env);
        ACCSManager.bindApp(this, appkey, "ttidzorotest",
                new IAppReceiver() {
                    private final Map<String, String> SERVICES = new HashMap<String, String>() {

                        {
                            put("accs", "com.taobao.taobao.CallbackService");
                            put("accs-console", "com.taobao.taobao.CallbackService");
                            put("agooSend", "org.android.agoo.accs.AgooService");
                            put("agooAck", "org.android.agoo.accs.AgooService");
                            put("agooTokenReport", "org.android.agoo.accs.AgooService");
                        }
                    };

                    @Override
                    public void onData(String userId, String dataId, byte[] data) {
                        Log.i("info", "onData()");
                    }

                    @Override
                    public void onBindApp(int errorCode) {
                        Log.i("info", "onBindApp(): " + errorCode);
                        ChannelBindHelper.getInstance().registerChannel(
                                com.ut.device.UTDevice.getUtdid(ArgraceApplication.this),
                                "AGOO",
                                errorCode == 200);
                    }

                    @Override
                    public void onUnbindApp(int errorCode) {
                        Log.i("info", "onUnbindApp(): " + errorCode);
                    }

                    @Override
                    public void onBindUser(String userId, int errorCode) {
                        Log.i("info", "onBindUser(): " + userId + "/" + errorCode);
                    }

                    @Override
                    public void onUnbindUser(int errorCode) {
                        Log.i("info", "onUnbindUser(): " + errorCode);
                    }

                    @Override
                    public void onSendData(String dataId, int errorCode) {
                        Log.i("info", "onSendData(): " + errorCode);
                    }

                    @Override
                    public String getService(String serviceId) {
                        Log.i("info", "getService(),+ serviceId" + serviceId);
                        String service = SERVICES.get(serviceId);
                        return service;
                    }

                    @Override
                    public Map<String, String> getAllServices() {
                        return SERVICES;
                    }
                });
    }

    private void initAlinkSDK() {
        AlinkSDK.setLogLevel(ALog.LEVEL_DEBUG);

        // init account & open sdk
        {

            IAlinkLoginCallback alinkLoginCallback = new IAlinkLoginCallback() {
                @Override
                public void onSuccess() {
                    Toast.makeText(ArgraceApplication.this, "账号初始化成功", Toast.LENGTH_SHORT).show();
                    Log.i("info", "账号初始化成功");
                }

                @Override
                public void onFailure(int code, String message) {
                    Toast.makeText(ArgraceApplication.this, "账号初始化异常: " + message, Toast.LENGTH_LONG).show();
                    Log.i("info", "账号初始化失败,code = " + code + ".message:" + message);
                }
            };

            Environment env = Environment.ONLINE;    //线上环境

            OALoginBusiness oaBiz = new OALoginBusiness();
            oaBiz.init(getApplicationContext(), env, alinkLoginCallback);

//注册到AlinkSDK
            AlinkSDK.init(this, appkey, oaBiz);
        }

        // add image support with fresco
        BizPackageHolder bizPackageHolder = RNGlobalConfig.getBizPackageHolder();
        bizPackageHolder.addPackage(new FrescoPackage());

        // init boneKit if you need
        {
            AlinkSDK.setCdnEnv(cdnEnv);
            String appVersion = getAppVersion(this);
            AlinkSDK.initBoneKit(this, appkey, appVersion, true);
        }
    }

    static String getAppVersion(Context context) {
        String version = "";

        try {

            String packageName = context.getPackageName();

            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);

            version = packageInfo.versionName;

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return version;
    }

    static boolean isMainProcess(Context context) {

        int pid = android.os.Process.myPid();
        String processName = "";

        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                processName = appProcess.processName;
                break;
            }
        }

        String packageName = context.getPackageName();
        return (processName.equals(packageName));
    }

    private void initOkgo() {
        HttpHeaders headers = new HttpHeaders();
        //-----------------------------------------------------------------------------------//

        //必须调用初始化
        OkGo.init(this);

        //以下设置的所有参数是全局参数,同样的参数可以在请求的时候再设置一遍,那么对于该请求来讲,请求中的参数会覆盖全局参数
        //好处是全局参数统一,特定请求可以特别定制参数
        try {
            //以下都不是必须的，根据需要自行选择,一般来说只需要 debug,缓存相关,cookie相关的 就可以了
            OkGo.getInstance()

                    //打开该调试开关,控制台会使用 红色error 级别打印log,并不是错误,是为了显眼,不需要就不要加入该行
                    .debug("OkGo")

                    //如果使用默认的 60秒,以下三行也不需要传
                    .setConnectTimeout(OkGo.DEFAULT_MILLISECONDS)  //全局的连接超时时间
                    .setReadTimeOut(OkGo.DEFAULT_MILLISECONDS)     //全局的读取超时时间
                    .setWriteTimeOut(OkGo.DEFAULT_MILLISECONDS)    //全局的写入超时时间

                    //可以全局统一设置缓存模式,默认是不使用缓存,可以不传,具体其他模式看 github 介绍 https://github.com/jeasonlzy0216/
                    .setCacheMode(CacheMode.NO_CACHE)

                    //可以全局统一设置缓存时间,默认永不过期,具体使用方法看 github 介绍
                    .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)

                    //可以全局统一设置超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0
                    .setRetryCount(3)

                    //如果不想让框架管理cookie,以下不需要
//                .setCookieStore(new MemoryCookieStore())                //cookie使用内存缓存（app退出后，cookie消失）
                    .setCookieStore(new PersistentCookieStore())          //cookie持久化存储，如果cookie不过期，则一直有效

                    //可以设置https的证书,以下几种方案根据需要自己设置
//                    .setCertificates()                                  //方法一：信任所有证书（选一种即可）
//                    .setCertificates(getAssets().open("srca.cer"))      //方法二：也可以自己设置https证书（选一种即可）
//                    .setCertificates(getAssets().open("aaaa.bks"), "123456", getAssets().open("srca.cer"))//方法三：传入bks证书,密码,和cer证书,支持双向加密

                    //可以添加全局拦截器,不会用的千万不要传,错误写法直接导致任何回调不执行
//                    .addInterceptor(new Interceptor() {
//                        @Override
//                        public Response intercept(Chain chain) throws IOException {
//                            Request request = chain.request();
//                            Response response = chain.proceed(request);
//                            try {
//                                Response.Builder builder = response.newBuilder();
//                                Response clone = builder.build();
//                                if (!TextUtils.isEmpty(clone.message())) {
//                                }
//
//                                ResponseBody body = clone.body();
//                                if (body != null) {
//                                    MediaType mediaType = body.contentType();
//                                    if (mediaType != null) {
//                                        if (ToolsKit.isText(mediaType)) {
//                                            String resp = body.string();
//
//                                            JSONObject jsonObject = null;
//                                            try {
//                                                jsonObject = new JSONObject(resp);
//
//                                                if (jsonObject.has("happy")) {//幸福指数
//                                                    String happy = jsonObject.getString("happy");
//                                                    if (ToolsKit.isStringNotEmpty(happy)) {
//                                                        App.getInstance().refreshMainPageGroup = 1;
//                                                    }
//                                                }
//
//                                                //贝尔加
//
//                                            } catch (JSONException e) {
//                                                e.printStackTrace();
//                                            }
//                                            body = ResponseBody.create(mediaType, resp);
//
//                                            return response.newBuilder().body(body).build();
//                                        } else {
////                                                Log.e(tag, "content : " + " maybe [file part] , too large too print , ignored!");
//                                        }
//                                    }
//                                }
//                            } catch (Exception e) {
//                                OkLogger.e(e);
//                            } finally {
//                            }
//
//                            return response;
//                        }
//                    })

                    //这两行同上,不需要就不要传
                    .addCommonHeaders(headers)                                         //设置全局公共头
//                    .addCommonParams(params)
            ;                                          //设置全局公共参数
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private String APP_KEY = "5d52533ec4cd4f29a462b575927e556a";

    private void initYingShi() {
        EZOpenSDK.showSDKLog(true);
        EZOpenSDK.enableP2P(false);
        EZOpenSDK.initLib(this, APP_KEY, "");
    }

    private void sendMsg(String uuid, String key, String value) {
        //设备反转只有一个１
        value = "1";
        key = key.replaceAll("Switch", "TumblerSwitch");
        String method = "mtop.openalink.app.core.device.set.status";
        HashMap<String, Object> params = new HashMap<>();
        params.put("uuid", uuid);
        params.put("setParams", "{\"" + key + "\":\"" + value + "\"}");
        Log.i("syncDevice", "同步数据发送的数据是" + "{\"" + key + "\":\"" + value + "\"}" + "----" + uuid);
        AlinkHttpUtil.AlinkHttpRequest(method, params, new ALinkBusinessEx.IListener() {
            @Override
            public void onSuccess(TransitoryRequest transitoryRequest, TransitoryResponse transitoryResponse) {
                Log.i("info", "发送消息成功" + transitoryResponse.data);
//                getDeviceDetailInfo();
            }

            @Override
            public void onFailed(TransitoryRequest transitoryRequest, AError aError) {
                Log.i("info", "发送消息失败");
            }
        });
    }

    private void dosyncDevice(JSONObject obj) {
        if (!(obj == null || obj.getJSONObject("params") == null || obj.getJSONObject("params").getJSONObject("data") == null || obj.getJSONObject("params").getString("uuid") == null)) {
            String uuid = obj.getJSONObject("params").getString("uuid");
            List<LocalDb_DeviceSyncTable> beans_zhu = DataSupport.where("zhusheibeiuuid = ?", uuid).find(LocalDb_DeviceSyncTable.class);
            List<LocalDb_DeviceSyncTable> beans_fu = DataSupport.where("fushebeiuuid = ?", uuid).find(LocalDb_DeviceSyncTable.class);
            JSONObject obj_data = obj.getJSONObject("params").getJSONObject("data");
//            if (beans_zhu != null && beans_zhu.size() > 0) {
//                for (LocalDb_DeviceSyncTable entity : beans_zhu) {
//                    //主设备同步辅设备
//                    if (entity.getZhusheibeiuuid().equals(obj.getJSONObject("params").getString("uuid"))) {
//                        Key_ValueEntity zhu = JSON.parseObject(obj_data.getString(entity.getZhushebeijianzhi()), Key_ValueEntity.class);
//                        if (zhu != null) {
//                            getDeviceDetailInfo(entity.getFushebeiuuid(),entity.getFushebejianzhi(),zhu.getValue());
//                        }
//                    }
////                    //辅设备同步主设备
////                    if (entity.getFushebeiuuid().equals(obj.getJSONObject("params").getString("uuid"))) {
////                        Key_ValueEntity fu = JSON.parseObject(obj_data.getString(entity.getFushebejianzhi()), Key_ValueEntity.class);
////                        if (fu != null) {
////                            sendMsg(entity.getZhusheibeiuuid(), entity.getZhushebeijianzhi(), fu.getValue());
////                        }
////                    }
//                }
//                return;
//            }
            if (beans_fu != null && beans_fu.size() > 0) {
                for (LocalDb_DeviceSyncTable entity : beans_fu) {
                    List<LocalDb_ShuangKongFuSheBeiTable> shuangKongFuSheBeientity_lists = DataSupport.where("uuid = ? and property = ?", entity.getFushebeiuuid(), entity.getFushebejianzhi()).find(LocalDb_ShuangKongFuSheBeiTable.class);
                    if (shuangKongFuSheBeientity_lists != null && shuangKongFuSheBeientity_lists.size() > 0) {

                        Log.i("info","查询的本地状态的property是" + shuangKongFuSheBeientity_lists.get(0).getProperty() + "---" + shuangKongFuSheBeientity_lists.get(0).getValue());
//                        Key_ValueEntity value1 = JSON.parseObject(obj_data.getString("Switch_1"), Key_ValueEntity.class);
//                        Key_ValueEntity value2 = JSON.parseObject(obj_data.getString("Switch_2"), Key_ValueEntity.class);
//                        Key_ValueEntity value3 = JSON.parseObject(obj_data.getString("Switch_3"), Key_ValueEntity.class);
                        Key_ValueEntity value = JSON.parseObject(obj_data.getString(entity.getFushebejianzhi()), Key_ValueEntity.class);
                        Log.i("info","对比的数据是" + entity.getFushebejianzhi() + "---" + value.getValue());
                        //推送过来的数据和本地数据不相等，则说明按的设备的双控按键
//                        if (value1!=null && shuangKongFuSheBeientity_lists.get(0).getValue_1()!=null&& !value1.equals(shuangKongFuSheBeientity_lists.get(0).getValue_1())) {
//                            shuangKongFuSheBeientity_lists.get(0).setValue_1(value1.getValue());
//                            shuangKongFuSheBeientity_lists.get(0).updateAll("uuid = ? and property = ?",entity.getFushebeiuuid(), entity.getFushebejianzhi());
//                            sendMsg(entity.getZhusheibeiuuid(), entity.getZhushebeijianzhi(), value1.getValue());
//                        }
//                        if (value2!=null && shuangKongFuSheBeientity_lists.get(0).getValue_1()!=null&& !value2.equals(shuangKongFuSheBeientity_lists.get(0).getValue_2())) {
//                            shuangKongFuSheBeientity_lists.get(0).setValue_1(value2.getValue());
//                            shuangKongFuSheBeientity_lists.get(0).updateAll("uuid = ? and property = ?",entity.getFushebeiuuid(), entity.getFushebejianzhi());
//                            sendMsg(entity.getZhusheibeiuuid(), entity.getZhushebeijianzhi(), value2.getValue());
//                        }
//                        if (value3!=null && shuangKongFuSheBeientity_lists.get(0).getValue_1()!=null&& !value3.equals(shuangKongFuSheBeientity_lists.get(0).getValue_3())) {
//                            shuangKongFuSheBeientity_lists.get(0).setValue_1(value3.getValue());
//                            shuangKongFuSheBeientity_lists.get(0).updateAll("uuid = ? and property = ?",entity.getFushebeiuuid(), entity.getFushebejianzhi());
//                            sendMsg(entity.getZhusheibeiuuid(), entity.getZhushebeijianzhi(), value3.getValue());
//                        }
                        if (value != null && shuangKongFuSheBeientity_lists.get(0).getValue() != null && !value.getValue().equals(shuangKongFuSheBeientity_lists.get(0).getValue())) {
                            shuangKongFuSheBeientity_lists.get(0).setValue(value.getValue());
                            shuangKongFuSheBeientity_lists.get(0).updateAll("uuid = ? and property = ?", entity.getFushebeiuuid(), entity.getFushebejianzhi());
                            sendMsg(entity.getZhusheibeiuuid(), entity.getZhushebeijianzhi(), value.getValue());
                        }

                    } else {
                        LocalDb_ShuangKongFuSheBeiTable shuangKongFuSheBeientity = new LocalDb_ShuangKongFuSheBeiTable();
                        shuangKongFuSheBeientity.setUuid(entity.getFushebeiuuid());
//                        Key_ValueEntity value1 = JSON.parseObject(obj_data.getString("Switch_1"), Key_ValueEntity.class);
//                        Key_ValueEntity value2 = JSON.parseObject(obj_data.getString("Switch_2"), Key_ValueEntity.class);
//                        Key_ValueEntity value3 = JSON.parseObject(obj_data.getString("Switch_3"), Key_ValueEntity.class);
                        Key_ValueEntity value = JSON.parseObject(obj_data.getString(entity.getFushebejianzhi()), Key_ValueEntity.class);
                        if (value != null) {
                            shuangKongFuSheBeientity.setProperty(entity.getFushebejianzhi());
                            shuangKongFuSheBeientity.setValue(value.getValue());
                            Log.i("info", "保存的辅设备键值是" + shuangKongFuSheBeientity.getProperty() + "当前保存的辅设备本地状态" + value.getValue());
                            shuangKongFuSheBeientity.save();
                        }
//                        if (value1 != null) {
//                            shuangKongFuSheBeientity.setValue_1(value1.getValue());
//                        }
//                        if (value2 != null) {
//                            shuangKongFuSheBeientity.setValue_2(value2.getValue());
//                        }
//                        if (value3 != null) {
//                            shuangKongFuSheBeientity.setValue_3(value3.getValue());
//                        }
                    }
                }
                return;
            }
        }

    }

    private void doRelationDevice(JSONObject obj) {
        if (!(obj == null || obj.getJSONObject("params") == null || obj.getJSONObject("params").getJSONObject("data") == null || obj.getJSONObject("params").getString("uuid") == null)) {
            String uuid = obj.getJSONObject("params").getString("uuid");
            List<LocalDb_RelationDeviceTable> beans = DataSupport.where("uuid = ?", uuid).find(LocalDb_RelationDeviceTable.class);

            JSONObject obj_data = obj.getJSONObject("params").getJSONObject("data");
            //从数据库查找相关uuid的设备,
            if (beans != null && beans.size() > 0) {
                if (!beans.get(0).getUuid().equals(obj.getJSONObject("params").getString("uuid"))) {
                    return;
                }
                for (int i = 0; i < beans.size(); i++) {
                    com.alibaba.fastjson.JSONObject jsonobj_local = JSON.parseObject(beans.get(i).getTrigger_condition());
                    Key_ValueEntity bean_dianliang;
                    Key_ValueEntity bean_xinhao;
                    Key_ValueEntity bean_dianliang_local;
                    Key_ValueEntity bean_xinhao_local;
                    switch (beans.get(0).getModel()) {//因为查询到的都是同一设备，所以以第一个的model为当前mdoel
                        case ConstantConfigure.MODEL_YANWUTANCEQI:
                            Key_ValueEntity bean_smokealarm = JSON.parseObject(obj_data.getString("SmokeAlarm"), Key_ValueEntity.class);
                            bean_dianliang = JSON.parseObject(obj_data.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao = JSON.parseObject(obj_data.getString("Rssi"), Key_ValueEntity.class);
                            Key_ValueEntity bean_smokealarm_local = JSON.parseObject(jsonobj_local.getString("SmokeAlarm"), Key_ValueEntity.class);
                            bean_dianliang_local = JSON.parseObject(jsonobj_local.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao_local = JSON.parseObject(jsonobj_local.getString("Rssi"), Key_ValueEntity.class);
                            //判定条件SmokeAlarm状态达到预设，电量或者信号任一强度小于预设则触发
                            if (bean_smokealarm.equals(bean_smokealarm_local) && (bean_dianliang.compareValue(bean_dianliang_local) == -1
//                                    || bean_xinhao.compareValue(bean_xinhao_local) == -1
                            )) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_MENCIGANYING:
                            Key_ValueEntity menci_contactAlarm = JSON.parseObject(obj_data.getString("ContactAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity menci_tamperAlarm = JSON.parseObject(obj_data.getString("TamperAlarm"), Key_ValueEntity.class);
                            bean_dianliang = JSON.parseObject(obj_data.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao = JSON.parseObject(obj_data.getString("Rssi"), Key_ValueEntity.class);
                            Key_ValueEntity menci_contactAlarm_local = JSON.parseObject(jsonobj_local.getString("ContactAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity menci_tamperAlarm_local = JSON.parseObject(jsonobj_local.getString("TamperAlarm"), Key_ValueEntity.class);
                            bean_dianliang_local = JSON.parseObject(jsonobj_local.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao_local = JSON.parseObject(jsonobj_local.getString("Rssi"), Key_ValueEntity.class);
                            //判定条件ContactAlarm、TamperAlarm状态达到预设，电量或者信号任一强度小于预设则触发
//                            if (menci_contactAlarm.equals(menci_contactAlarm_local) && menci_tamperAlarm.equals(menci_tamperAlarm_local)
////                                    && (bean_dianliang.isEqualOrless(bean_dianliang_local) || bean_xinhao.isEqualOrless(bean_xinhao_local))
//                                    ) {
//                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
//                                utils.executeQingJing(bean);
//                            }
                            //修改判定条件为值关注门磁状态
                            if (menci_contactAlarm != null && menci_contactAlarm.equals(menci_contactAlarm_local)) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_MEIQITANCEQI:
                            Key_ValueEntity qiti_gasAlarm = JSON.parseObject(obj_data.getString("GasAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity qiti_gasAlarm_local = JSON.parseObject(jsonobj_local.getString("GasAlarm"), Key_ValueEntity.class);
                            if (qiti_gasAlarm.equals(qiti_gasAlarm_local)) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_RENTIGANYING:
                            Key_ValueEntity motionAlarm = JSON.parseObject(obj_data.getString("MotionAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity tamperAlarm = JSON.parseObject(obj_data.getString("TamperAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity motionAlarm_Local = JSON.parseObject(jsonobj_local.getString("MotionAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity tamperAlarm_Local = JSON.parseObject(jsonobj_local.getString("TamperAlarm"), Key_ValueEntity.class);
                            if (motionAlarm.equals(motionAlarm_Local) && tamperAlarm.equals(tamperAlarm_Local)) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_SANWEIDUOKONG:
                            Key_ValueEntity sanwei_1 = JSON.parseObject(obj_data.getString("Switch_1"), Key_ValueEntity.class);
                            Key_ValueEntity sanwei_2 = JSON.parseObject(obj_data.getString("Switch_2"), Key_ValueEntity.class);
                            Key_ValueEntity sanwei_3 = JSON.parseObject(obj_data.getString("Switch_3"), Key_ValueEntity.class);
                            Key_ValueEntity sanwei_1_Local = JSON.parseObject(jsonobj_local.getString("Switch_1"), Key_ValueEntity.class);
                            Key_ValueEntity sanwei_2_Local = JSON.parseObject(jsonobj_local.getString("Switch_2"), Key_ValueEntity.class);
                            Key_ValueEntity sanwei_3_Local = JSON.parseObject(jsonobj_local.getString("Switch_3"), Key_ValueEntity.class);
                            if (sanwei_1.compareValue(sanwei_1_Local) == 0 && sanwei_2.compareValue(sanwei_2_Local) == 0 && sanwei_3.compareValue(sanwei_3_Local) == 0) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_LIANGWEIDUOKONG:
                            Key_ValueEntity liangwei_1 = JSON.parseObject(obj_data.getString("Switch_1"), Key_ValueEntity.class);
                            Key_ValueEntity liangwei_2 = JSON.parseObject(obj_data.getString("Switch_2"), Key_ValueEntity.class);
                            Key_ValueEntity liangwei_1_Local = JSON.parseObject(jsonobj_local.getString("Switch_1"), Key_ValueEntity.class);
                            Key_ValueEntity liangwei_2_Local = JSON.parseObject(jsonobj_local.getString("Switch_2"), Key_ValueEntity.class);
                            if (liangwei_1.compareValue(liangwei_1_Local) == 0 && liangwei_2.compareValue(liangwei_2_Local) == 0) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_YIWEIDUOKONG:
                            Key_ValueEntity yiwei = JSON.parseObject(obj_data.getString("Switch"), Key_ValueEntity.class);
                            Key_ValueEntity yiwei_Local = JSON.parseObject(jsonobj_local.getString("Switch"), Key_ValueEntity.class);
                            if (yiwei.compareValue(yiwei_Local) == 0) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_10ACHAZUO:
                            Key_ValueEntity tongsuo = JSON.parseObject(obj_data.getString("SwitchChildLock"), Key_ValueEntity.class);
                            Key_ValueEntity chazuo_1 = JSON.parseObject(obj_data.getString("SwitchMultiple_1"), Key_ValueEntity.class);
                            Key_ValueEntity chazuo_2 = JSON.parseObject(obj_data.getString("SwitchMultiple_2"), Key_ValueEntity.class);
                            Key_ValueEntity dianliu = JSON.parseObject(obj_data.getString("RmsCurrent"), Key_ValueEntity.class);
                            Key_ValueEntity dianya = JSON.parseObject(obj_data.getString("RmsVoltage"), Key_ValueEntity.class);
                            Key_ValueEntity dianliang = JSON.parseObject(obj_data.getString("SumElectric"), Key_ValueEntity.class);
                            Key_ValueEntity tongsuo_Local = JSON.parseObject(jsonobj_local.getString("SwitchChildLock"), Key_ValueEntity.class);
                            Key_ValueEntity chazuo_1_Local = JSON.parseObject(jsonobj_local.getString("SwitchMultiple_1"), Key_ValueEntity.class);
                            Key_ValueEntity chazuo_2_Local = JSON.parseObject(jsonobj_local.getString("SwitchMultiple_2"), Key_ValueEntity.class);
                            Key_ValueEntity dianliu_Local = JSON.parseObject(jsonobj_local.getString("RmsCurrent"), Key_ValueEntity.class);
                            Key_ValueEntity dianya_Local = JSON.parseObject(jsonobj_local.getString("RmsVoltage"), Key_ValueEntity.class);
                            Key_ValueEntity dianliang_Local = JSON.parseObject(jsonobj_local.getString("SumElectric"), Key_ValueEntity.class);
//                            //三个锁开关状态相同，三个数值大于预设
//                            if (tongsuo.compareValue(tongsuo_Local) == 0 && chazuo_1.compareValue(chazuo_1_Local) == 0 && chazuo_2.compareValue(chazuo_2_Local) == 0
//                                    && dianliu.isEqualOrGreater(dianliu_Local) && dianya.isEqualOrGreater(dianya_Local) && dianliang.isEqualOrGreater(dianliang_Local)
//                                    ) {
//                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
//                                utils.executeQingJing(bean);
//                            }
                            //修改为根据电流变化处理关联
                            if (dianliu_Local != null && dianliu_Local.getValue().equals("0") && dianliu != null && dianliu.getValue().equals("0")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            if (dianliu_Local != null && !dianliu_Local.getValue().equals("0") && dianliu != null && !dianliu.getValue().equals("0")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_KAIHELIANDIANJI:
                            Key_ValueEntity curtainPosition = JSON.parseObject(obj_data.getString("CurtainPosition"), Key_ValueEntity.class);
                            Key_ValueEntity curtainPosition_local = JSON.parseObject(jsonobj_local.getString("CurtainPosition"), Key_ValueEntity.class);
                            if (curtainPosition.equals(curtainPosition_local)) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_XINFENGKONGZHIQI:
                            Key_ValueEntity windSpeed = JSON.parseObject(obj_data.getString("WindSpeed"), Key_ValueEntity.class);
                            Key_ValueEntity windSpeed_local = JSON.parseObject(jsonobj_local.getString("WindSpeed"), Key_ValueEntity.class);
                            Key_ValueEntity xinfingji_switch = JSON.parseObject(obj_data.getString("Switch"), Key_ValueEntity.class);
                            Key_ValueEntity xinfingji_switch_Local = JSON.parseObject(jsonobj_local.getString("Switch"), Key_ValueEntity.class);
                            if (windSpeed.equals(windSpeed_local) && xinfingji_switch.compareValue(xinfingji_switch_Local) == 0) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_SHUIDINUAN:
                            Key_ValueEntity shuidinuan_tem = JSON.parseObject(obj_data.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity shuidinuan_tem_local = JSON.parseObject(jsonobj_local.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity shuidinuan_switch = JSON.parseObject(obj_data.getString("Switch"), Key_ValueEntity.class);
                            Key_ValueEntity shuidinuan_switch_Local = JSON.parseObject(jsonobj_local.getString("Switch"), Key_ValueEntity.class);
                            if (shuidinuan_tem.equals(shuidinuan_tem_local) && shuidinuan_switch.compareValue(shuidinuan_switch_Local) == 0) {
                                Log.i("info", "执行了请求id= " + beans.get(i).getQingJingTable_id());
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_SUIJINTANCEQI:
                            Key_ValueEntity shuijin_contactAlarm = JSON.parseObject(obj_data.getString("WaterAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity shuijin_tamperAlarm = JSON.parseObject(obj_data.getString("TamperAlarm"), Key_ValueEntity.class);
                            bean_dianliang = JSON.parseObject(obj_data.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao = JSON.parseObject(obj_data.getString("Rssi"), Key_ValueEntity.class);
                            Key_ValueEntity shuijin_contactAlarm_local = JSON.parseObject(jsonobj_local.getString("WaterAlarm"), Key_ValueEntity.class);
                            Key_ValueEntity shuijintamperAlarm_local = JSON.parseObject(jsonobj_local.getString("TamperAlarm"), Key_ValueEntity.class);
                            bean_dianliang_local = JSON.parseObject(jsonobj_local.getString("BatteryPercentage"), Key_ValueEntity.class);
                            bean_xinhao_local = JSON.parseObject(jsonobj_local.getString("Rssi"), Key_ValueEntity.class);
                            //WaterAlarm、TamperAlarm，电量或者信号任一强度小于预设则触发
                            if (shuijin_contactAlarm.equals(shuijin_contactAlarm_local) && shuijin_tamperAlarm.equals(shuijintamperAlarm_local) && (bean_dianliang.isEqualOrless(bean_dianliang_local) || bean_xinhao.isEqualOrless(bean_xinhao_local))) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_PM25CHUANGANQI:
                            Key_ValueEntity voc_currentHumidity = JSON.parseObject(obj_data.getString("CurrentHumidity"), Key_ValueEntity.class);
                            Key_ValueEntity voc_CurrentTemperature = JSON.parseObject(obj_data.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity voc_pm25 = JSON.parseObject(obj_data.getString("PM25"), Key_ValueEntity.class);
                            Key_ValueEntity voc_tvoc = JSON.parseObject(obj_data.getString("TVOC"), Key_ValueEntity.class);
                            Key_ValueEntity voc_currentHumidity_local = JSON.parseObject(jsonobj_local.getString("CurrentHumidity"), Key_ValueEntity.class);
                            Key_ValueEntity voc_CurrentTemperature_local = JSON.parseObject(jsonobj_local.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity voc_pm25_local = JSON.parseObject(jsonobj_local.getString("PM25"), Key_ValueEntity.class);
                            Key_ValueEntity voc_tvoc_local = JSON.parseObject(jsonobj_local.getString("TVOC"), Key_ValueEntity.class);
                            //高于预设值触发
//                            if (voc_currentHumidity.isEqualOrGreater(voc_currentHumidity_local) && voc_CurrentTemperature.isEqualOrGreater(voc_CurrentTemperature_local) && voc_pm25.isEqualOrGreater(voc_pm25_local) && voc_tvoc.isEqualOrGreater(voc_tvoc_local)) {
//                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
//                                utils.executeQingJing(bean);
//                            }
                            //修改为大于50和小于30触发
                            if (voc_pm25 != null && voc_pm25_local != null && voc_pm25_local.equals("50") && voc_pm25.isEqualOrGreater("50")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            if (voc_pm25 != null && voc_pm25_local != null && voc_pm25_local.equals("30") && voc_pm25.isEqualOrless("30")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_KONGQIHEZI:
                            Key_ValueEntity kongqihezi_currentHumidity = JSON.parseObject(obj_data.getString("CurrentHumidity"), Key_ValueEntity.class);
                            Key_ValueEntity kongqihezi_CurrentTemperature = JSON.parseObject(obj_data.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity kongqihezi_pm25 = JSON.parseObject(obj_data.getString("PM25"), Key_ValueEntity.class);
                            bean_dianliang = JSON.parseObject(obj_data.getString("BatteryPercentage"), Key_ValueEntity.class);
                            Key_ValueEntity kongqihezi_currentHumidity_local = JSON.parseObject(jsonobj_local.getString("CurrentHumidity"), Key_ValueEntity.class);
                            Key_ValueEntity kongqihezi_CurrentTemperature_local = JSON.parseObject(jsonobj_local.getString("CurrentTemperature"), Key_ValueEntity.class);
                            Key_ValueEntity kongqihezi_pm25_local = JSON.parseObject(jsonobj_local.getString("PM25"), Key_ValueEntity.class);
                            bean_dianliang_local = JSON.parseObject(jsonobj_local.getString("BatteryPercentage"), Key_ValueEntity.class);
//                            //只有电量是小于预设，其他高于预设触发
//                            if (kongqihezi_currentHumidity.isEqualOrGreater(kongqihezi_currentHumidity_local) && kongqihezi_CurrentTemperature.isEqualOrGreater(kongqihezi_CurrentTemperature_local) && kongqihezi_pm25.isEqualOrGreater(kongqihezi_pm25_local) && bean_dianliang.isEqualOrless(bean_dianliang_local)) {
//                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
//                                utils.executeQingJing(bean);
//                            }
                            //修改为大于50和小于30触发
                            if (kongqihezi_pm25 != null && kongqihezi_pm25_local != null && kongqihezi_pm25_local.equals("50") && kongqihezi_pm25.isEqualOrGreater("50")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            if (kongqihezi_pm25 != null && kongqihezi_pm25_local != null && kongqihezi_pm25_local.equals("30") && kongqihezi_pm25.isEqualOrless("30")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                            break;
                        case ConstantConfigure.MODEL_KONGTIAOZHUANHUANQI:
                            String property = beans.get(i).getProperty();
                            Key_ValueEntity kongtiao_currentTemperature = JSON.parseObject(obj_data.getString("CurrentTemperature_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_switch = JSON.parseObject(obj_data.getString("Switch_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_windSpeed = JSON.parseObject(obj_data.getString("WorkMode_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_workModel = JSON.parseObject(obj_data.getString("WindSpeed_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_currentTemperature_local = JSON.parseObject(jsonobj_local.getString("CurrentTemperature_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_switch_local = JSON.parseObject(jsonobj_local.getString("Switch_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_windSpeed_local = JSON.parseObject(jsonobj_local.getString("WorkMode_" + property), Key_ValueEntity.class);
                            Key_ValueEntity kongtiao_workModel_local = JSON.parseObject(jsonobj_local.getString("WindSpeed_" + property), Key_ValueEntity.class);
//温度相同，并且模式，风速都相同则处理
                            if (kongtiao_switch.equals(kongtiao_switch_local) && kongtiao_currentTemperature.equals(kongtiao_currentTemperature_local) && kongtiao_windSpeed.equals(kongtiao_windSpeed_local) && kongtiao_workModel.equals(kongtiao_workModel_local)) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                utils.executeQingJing(bean);
                            }
                        case ConstantConfigure.MODEL_ZHINENGMENSUO:
                            if (obj_data.getJSONObject("OpenDoor") == null || obj_data.getJSONObject("OpenDoor").getJSONObject("value") == null) {
                                return;
                            }
                            String mensuo_OpenDoor_value = obj_data.getJSONObject("OpenDoor").getJSONObject("value").getString("UserType");
                            if (mensuo_OpenDoor_value != null && mensuo_OpenDoor_value.equals("1")) {
                                LocalDb_QingJingTable bean = DataSupport.find(LocalDb_QingJingTable.class, beans.get(i).getQingJingTable_id());
                                Log.i("info", "执行了门锁的场景" + bean.getId());
                                utils.executeQingJing(bean);
                            }
                            break;
                    }
                }
            }
        }
    }
}

